package com.evan.uyclub.AppStore;

import static com.umeng.commonsdk.stateless.UMSLEnvelopeBuild.mContext;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.evan.uyclub.R;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.squareup.picasso.Picasso;

import java.util.List;

public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> {


    private List<ListReturn> mAppList;
    private View view;
    private ListReturn appClass;
    private BottomSheetDialog handle_app;
    private View handle_view;
    private ViewHolder holder;

    public AppAdapter(List<ListReturn> date_list) {
        mAppList = date_list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.app_item, parent, false);
        holder = new ViewHolder(view);
        holder.itemView.setOnClickListener(v -> {
            //暂时存到UserClass
            String id = holder.item_download_url.getText().toString(); //应用id
            Log.e("id", id);

        });
        return holder;
    }

    @Override
    public void onBindViewHolder(AppAdapter.ViewHolder holder, int position) {
        //获取包装内的每条信息并显示给控件
        appClass = mAppList.get(position);

        Picasso.with(mContext).load(appClass.getIconApp()).noPlaceholder().error(R.mipmap.ic_load).into(holder.item_icon);
        holder.item_name.setText(appClass.getNameApp());
        holder.item_referral.setText(appClass.getReferralApp());
        holder.item_download_url.setText(appClass.getDownloadUrl());
    }

    @Override
    public int getItemCount() {
        return mAppList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView item_icon, item_truncation_one, item_truncation_two, item_truncation_three;
        TextView item_name, item_referral, item_download_url, App_Dow_Text;
        CardView App_Dow;

        public ViewHolder(View view) {
            super(view);
            item_icon = (ImageView) view.findViewById(R.id.item_icon);
            item_name = (TextView) view.findViewById(R.id.item_name);
            item_referral = (TextView) view.findViewById(R.id.item_referral);
            item_download_url = (TextView) view.findViewById(R.id.item_download_url);
            App_Dow = (CardView) view.findViewById(R.id.App_Dow);
            App_Dow_Text = (TextView) view.findViewById(R.id.App_DowText);
        }
    }
}